<?php

class BrandModel extends Model{
	
	public $table = 'brand';
	public $validate = array(
		array('bname','nonull','品牌名称不能为空',2,3),
	);
	
	//自动完成
//	public $auto = array(
//		array('logo','_logo','method',2,3),
//	
//	);
	//构造上传方法
//	public function _logo(){
//		$upload = new Upload();
//		$file = $upload->upload();
//		if($file){
//			$img = new image();
//			$info = $img->thumb($file[0]['path']);
//			return $info;
//		}else{
//			if($blogo=Q('post.blogo')) return $blogo;
//		}
//	}
	//添加brand
	public function add_data(){
		if(!$this->create()) return false;
		//logo不能同名
		$bname = Q('post.bname');
		if($this->get_one_logo(array('bname'=>$bname))){
			$this->error = $bname . 'logo已存在';
			return false;
		}
		return $this->add();
	}
	
	//获取所有logo数据
	public function get_all_logo($where=Null,$needPage=FALSE){
		if($needPage){
		//分页类用法
		//总条数
			$total=$this->where($where)->count();
			//2表示每页取多少条，3表示页码的数量
			$pageObj = new Page($total,6,3);
			//显示分页，与验证码code一样，用show();
			$page = $pageObj->show();
			//分页类算出limit
			$limit = $pageObj->limit();
			//在使用分页类的时候一定要注意limit
			$data = $this->where($where)->limit($limit)->all();
			$data['page'] = $page;
			}else{
				$data = $this->order('sort ASC')->where($where)->all();
		}
		return $data;

	}
	//获取一条logo数据
	public function get_one_logo($where=Null,$field=Null){
		return $this->where($where)->field($field)->find();
	}
	
	//修改品牌
	public function update_br($where=Null){
		return $this->where($where)->save();
	}
	
	//删除品牌
	public function delete_br($where){
		return $this->where($where)->delete();
	}
	
	
	
	
}//end
